<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="format-detection" content="telephone=no, email=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <title>Title</title>
    <style>
        li {
            display: none;
        }

        .active {
            background: blue;
        }


    </style>
</head>
<body>

<div class="box" id="box">
    <input type="button" value="按钮1" class="active"/>
    <input type="button" value="按钮2"/>
    <input type="button" value="按钮3"/>
    <div class="show">
        <div>11111</div>
        <div>22222222222</div>
        <div>333333333333</div>
    </div>
</div>
<div class="box" id="box2">
    <input type="button" value="按钮1" class="active"/>
    <input type="button" value="按钮2"/>
    <input type="button" value="按钮3"/>
    <ul class="show">
        <li style="display: block;">11111</li>
        <li>22222</li>
        <li>33333</li>
    </ul>
</div>


<script>
    function Tab(id) {
        var oBox = document.querySelector(id);
        this.aInp = oBox.querySelectorAll('input')
        this.ali = oBox.querySelectorAll('li')
    }
    Tab.prototype.init = function () {
        for (var i = 0; i < this.aInp.length; i++) {
            this.aInp[i].index = i;
            var This = this;
            this.aInp[i].onclick = function () {
                This.func(this)
            };
        }
    }

    Tab.prototype.func = function (me) {
        for (var i = 0; i < this.aInp.length; i++) {
            this.aInp[i].className = "";
            this.ali[i].style.display = "none"
        }
        me.className = "active";
        this.ali[me.index].style.display = "block"
    }
    window.onload = function () {
        var t1 = new Tab("box1")
        t1.init();
        var t2 = new Tab("box2")
        t2.init()
    };
</script>
</body>
</html>